package org.zjt.platform.springbootreactivedemo.config.endpoint;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.Random;

/**
 * Description:
 *
 * @author juntao.zhang
 * Date: 2018-06-13 上午10:27
 * @see
 * {@link ReactiveHealthIndicatorRegistry} {@link HealthIndicator} {@link ReactiveHealthIndicator} {@link HealthIndicator} {@link AbstractReactiveHealthIndicator}
 */
@Component
public class MyReactiveHealthIndicator implements ReactiveHealthIndicator {

    private Random random = new Random();

    @Override
    public Mono<Health> health() {
        if (random.nextInt(10) %2 ==0)
            return Mono.just(Health.down().withDetail("code","网络异常").build());
        return Mono.just(Health.up().build());
    }
}
